﻿// WhiteTestDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "WhiteTestDlg.h"
#include "afxdialogex.h"


// CWhiteTestDlg 对话框

IMPLEMENT_DYNAMIC(CWhiteTestDlg, CDialogEx)

CWhiteTestDlg::CWhiteTestDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_WHITE, pParent)
	, m_bFlag1(FALSE)
	, m_bScanX(FALSE)
	, m_bScanY(FALSE)
	, m_nScanDis(0)
	, m_nThreshold(0)
	, m_nFilter(0)
	, m_bFlag2(FALSE)
	, m_dHigh(0)
	, m_dLow(0)
	, WhiteRectX(0)
	, WhiteRectY(0)
	, WhiteRectW(0)
	, WhiteRectH(0)
	, IICFlag(FALSE)
	, FW_SlaveAdd(_T(""))
	, IICLength(0)
	, IICMode(0)
	, WhiteCutFlag(FALSE)
	, lightflag(FALSE)
	, lightx(0)
	, lighty(0)
	, lightw(0)
	, lighth(0)
{

}

CWhiteTestDlg::~CWhiteTestDlg()
{
}

void CWhiteTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK1, m_bFlag1);
	DDX_Check(pDX, IDC_CHECK2, m_bScanX);
	DDX_Check(pDX, IDC_CHECK3, m_bScanY);
	DDX_Text(pDX, IDC_EDIT1, m_nScanDis);
	DDX_Text(pDX, IDC_EDIT2, m_nThreshold);
	DDX_Text(pDX, IDC_EDIT3, m_nFilter);
	DDX_Check(pDX, IDC_CHECK4, m_bFlag2);
	DDX_Text(pDX, IDC_EDIT_HIGH, m_dHigh);
	DDX_Text(pDX, IDC_EDIT_LOW, m_dLow);
	DDX_Text(pDX, IDC_EDIT4, WhiteRectX);
	DDX_Text(pDX, IDC_EDIT6, WhiteRectY);
	DDX_Text(pDX, IDC_EDIT5, WhiteRectW);
	DDX_Text(pDX, IDC_EDIT7, WhiteRectH);
	DDX_Check(pDX, IDC_CHECK5, IICFlag);
	DDX_Text(pDX, IDC_EDIT8, FW_SlaveAdd);
	DDX_Text(pDX, IDC_EDIT9, IICLength);
	DDX_CBIndex(pDX, IDC_COMBO1, IICMode);
	DDX_Check(pDX, IDC_CHECK6, WhiteCutFlag);
	DDX_Check(pDX, IDC_CHECK7, lightflag);
	DDX_Text(pDX, IDC_EDIT10, lightx);
	DDX_Text(pDX, IDC_EDIT12, lighty);
	DDX_Text(pDX, IDC_EDIT11, lightw);
	DDX_Text(pDX, IDC_EDIT13, lighth);
}


BEGIN_MESSAGE_MAP(CWhiteTestDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CWhiteTestDlg::OnBnClickedButtonSave)
END_MESSAGE_MAP()


// CWhiteTestDlg 消息处理程序


BOOL CWhiteTestDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	ReadConfigIni();

	if (gSystemMgr.isAdmin)
	{
		// 获取当前窗口的第一个子控件
		CWnd* pChild = GetTopWindow();
		while (pChild != NULL)
		{
			// 禁用当前子控件
			pChild->EnableWindow(TRUE);
			// 获取下一个子控件
			pChild = pChild->GetNextWindow();
		}
	}
	else
	{
		// 获取当前窗口的第一个子控件
		CWnd* pChild = GetTopWindow();
		while (pChild != NULL)
		{
			// 禁用当前子控件
			pChild->EnableWindow(FALSE);
			// 获取下一个子控件
			pChild = pChild->GetNextWindow();
		}
	}

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CWhiteTestDlg::OnCancel()
{


	CDialogEx::OnCancel();
}


void CWhiteTestDlg::OnBnClickedButtonSave()
{
	SaveEditValueToConfig();
}

void CWhiteTestDlg::ReadConfigIni()
{
	m_bFlag1 = gSystemMgr.m_nStainTestFlag;
	m_bScanX = gSystemMgr.m_nScanXFlag;
	m_bScanY = gSystemMgr.m_nScanYFlag;
	m_nScanDis = gSystemMgr.m_nScanDistance;
	m_nThreshold = gSystemMgr.m_nScanThreshold;
	m_nFilter = gSystemMgr.m_nFilterClose;

	m_bFlag2 = gSystemMgr.m_nBadPointTestFlag;
	m_dHigh = gSystemMgr.m_fHighLimit;
	m_dLow = gSystemMgr.m_fLowLimit;

	WhiteRectX = gSystemMgr.WhiteRectX;
	WhiteRectY = gSystemMgr.WhiteRectY;
	WhiteRectW = gSystemMgr.WhiteRectW;
	WhiteRectH = gSystemMgr.WhiteRectH;

	FW_SlaveAdd = gSystemMgr.FW_SlaveAdd;
	IICFlag = gSystemMgr.IICFlag;

	IICLength = gSystemMgr.IICLength;
	IICMode = gSystemMgr.IICMode;

	WhiteCutFlag = gSystemMgr.WhiteCutFlag;

	lightflag = gSystemMgr.lightflag;
	lightx = gSystemMgr.lightx;
	lighty = gSystemMgr.lighty;
	lightw = gSystemMgr.lightw;
	lighth = gSystemMgr.lighth;

	UpdateData(FALSE);
}

void CWhiteTestDlg::SaveEditValueToConfig()
{
	UpdateData(TRUE);

	gSystemMgr.m_nStainTestFlag = m_bFlag1;
	gSystemMgr.m_nScanXFlag = m_bScanX;
	gSystemMgr.m_nScanYFlag = m_bScanY;
	gSystemMgr.m_nScanDistance = m_nScanDis;
	gSystemMgr.m_nScanThreshold = m_nThreshold;
	gSystemMgr.m_nFilterClose = m_nFilter;
	gSystemMgr.m_nBadPointTestFlag = m_bFlag2;
	gSystemMgr.m_fHighLimit = m_dHigh;
	gSystemMgr.m_fLowLimit = m_dLow;

	gSystemMgr.WhiteRectX = WhiteRectX;
	gSystemMgr.WhiteRectY = WhiteRectY;
	gSystemMgr.WhiteRectW = WhiteRectW;
	gSystemMgr.WhiteRectH = WhiteRectH;

	gSystemMgr.FW_SlaveAdd = FW_SlaveAdd;
	gSystemMgr.IICFlag = IICFlag;

	gSystemMgr.IICLength = IICLength;
	gSystemMgr.IICMode = IICMode;

	gSystemMgr.WhiteCutFlag = WhiteCutFlag;

	gSystemMgr.lightflag = lightflag;
	gSystemMgr.lightx = lightx;
	gSystemMgr.lighty = lighty;
	gSystemMgr.lightw = lightw;
	gSystemMgr.lighth = lighth;

	CString cstr;
	cstr.Format(L"%d", gSystemMgr.lightflag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"lightflag", cstr);
	cstr.Format(L"%d", gSystemMgr.lightx); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"lightx", cstr);
	cstr.Format(L"%d", gSystemMgr.lighty); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"lighty", cstr);
	cstr.Format(L"%d", gSystemMgr.lightw); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"lightw", cstr);
	cstr.Format(L"%d", gSystemMgr.lighth); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"lighth", cstr);


	cstr.Format(L"%d", gSystemMgr.WhiteCutFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"WhiteCutFlag", cstr);

	cstr.Format(L"%d", gSystemMgr.IICLength); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"IICLength", cstr);
	cstr.Format(L"%d", gSystemMgr.IICMode); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"IICMode", cstr);

	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"FW_SlaveAdd", gSystemMgr.FW_SlaveAdd);
	cstr.Format(L"%d", gSystemMgr.IICFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"IICFlag", cstr);

	cstr.Format(L"%d", gSystemMgr.WhiteRectX); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"WhiteRectX", cstr);
	cstr.Format(L"%d", gSystemMgr.WhiteRectY); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"WhiteRectY", cstr);
	cstr.Format(L"%d", gSystemMgr.WhiteRectW); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"WhiteRectW", cstr);
	cstr.Format(L"%d", gSystemMgr.WhiteRectH); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"WhiteRectH", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nStainTestFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nStainTestFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nScanXFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nScanXFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nScanYFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nScanYFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nScanDistance); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nScanDistance", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nScanThreshold); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nScanThreshold", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nFilterClose); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nFilterClose", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nBadPointTestFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_nBadPointTestFlag", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_fHighLimit); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_fHighLimit", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_fLowLimit); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"WhiteSetting", L"m_fLowLimit", cstr);

}
